﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.HomeServer.Controls.QSM;
using WhsFacebook.Net.Contracts;

namespace WhsFacebook.Whs.Service.Submitters
{
    public sealed class StorageSubmitter : InfoSubmitter<WhsStorageInfo>
    {
        #region instance

        public static StorageSubmitter Instance
        {
            get; private set;
        }

        static StorageSubmitter()
        {
            Instance = new StorageSubmitter();
        }

        #endregion

        protected override WhsStorageInfo DoSubmitInternal()
        {
            var r = new WhsStorageInfo()
            {
                InstanceId = WhsFacebookRegistry.GetInstanceId(),
                AppFoldersSize = QSMMgr.GetAppFoldersSize(),
                BackupSize = QSMMgr.GetBackupSize(),
                OperatingSystemSize = QSMMgr.GetOperatingSystemSize(),
                StorageFreeSpace = QSMMgr.GetStorageFreeSpace(),
                StorageSize = QSMMgr.GetStorageSize(),
                StorageUsedSpace = QSMMgr.GetStorageUsedSpace(),
            };

            QSMMgr.GetSharedFoldersSize(out r.SharedFoldersSize, out r.SharedFoldersDupSize);

            // submit
            using (var wc = new WhsFacebookServiceClientFactory())
            {
                wc.CreateChannel().UpdateStorageInfo(r);
            }

            return r;
        }

        private StorageSubmitter()
        {
            
        }
    }
}
